<!-- 整数输入组 import InputNumber from '@/components/InputNumber'  <InputNumber v-model="query.priceRange"></InputNumber> -->
<template>
  <span class="input-number-group">
    <el-input v-model="startNum" :size="size" :style="{width: width}" @change="onStartNumChange" type="number"></el-input>
    <span class="group-cen-word" style="margin: 0 3px;"><i class="el-icon-minus"></i></span>
    <el-input v-model="endNum" :size="size" :style="{width: width}" @change="onEndNumChange" type="number"></el-input>
  </span>
</template>

<script>
export default {
  name: 'InputNumber',
  components: {},
  data () {
    return {
      originStartNum: '',
      startNum: '',
      originEndNum: '',
      endNum: '',
      numReg: /^([1-9]\d*|[0]{1,1})$/
    }
  },
  props: {
    value: {
      type: Array,
      default: () => []
    },
    width: {
      type: String,
      default: '100px'
    },
    size: {
      type: String,
      default: 'medium'
    }
  },
  watch: {},
  computed: {},
  mounted () {
    if (this.value && Array.isArray(this.value) && this.value.length > 0) {
      this.originStartNum = this.startNum = this.value[0]
      this.originEndNum = this.endNum = this.value[1]
      if (this.value[0] > this.value[1]) {
        console.warn('开始数据不得大于结束数据')
      }
    }
  },
  methods: {
    onStartNumChange (val) {
      if (val && this.endNum && val > this.endNum) {
        this.startNum = this.endNum
      }
      this.onEmit()
    },
    onEndNumChange (val) {
      if (val && this.startNum && val < this.startNum) {
        this.endNum = this.startNum
      }
      this.onEmit()
    },
    onEmit () {
      let value = [this.startNum, this.endNum]
      this.$emit('input', value)
    }
  }
}

</script>
<style lang='scss' scoped>
</style>
